import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router) // 注册vue插件

// import ImportComponent from '@/views/import'

/* Layout */
import Layout from '@/layout'
import departmentsRouter from './modules/departments'
import employeesRouter from './modules/employees'
import settingRouter from './modules/setting'
import salarysRouter from './modules/salarys'
import socialRouter from './modules/social'
import attendancesRouter from './modules/attendances'
import approvalsRouter from './modules/approvals'
import permissionRouter from './modules/permission'

// 动态路由：保存需要权限控制的路由
// 组合动态路由模块
export const asyncRoutes = [
  departmentsRouter,
  settingRouter,
  employeesRouter,
  permissionRouter,
  salarysRouter,
  socialRouter,
  attendancesRouter,
  approvalsRouter
]

// 静态路由, 项目中每个用户都可以访问的功能
export const constantRoutes = [
  {
    path: '/login',
    component: () => import(/* webpackChunkName: "login" */'@/views/login/index'), // 路由懒加载
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/import',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/import'),
        // component: ImportComponent,
        hidden: true
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  }
  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  // routes: [...constantRoutes, ...asyncRoutes]
  routes: [...constantRoutes] // 只保留静态页面，显示在左侧菜单栏
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() { // 重置路由
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router

